package com.ourcraft.informationcollectionsystem.service.common;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ourcraft.informationcollectionsystem.entity.Company;
import com.ourcraft.informationcollectionsystem.entity.Role;
import com.ourcraft.informationcollectionsystem.entity.User;
import com.ourcraft.informationcollectionsystem.mapper.CompanyMapper;
import com.ourcraft.informationcollectionsystem.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommonServiceImpl implements CommonService {
    @Autowired
    RoleMapper roleMapper;
    @Autowired
    CompanyMapper companyMapper;

    @Override
    public List<Role> getAllRoles()
    {
        return roleMapper.selectList(null);
    }

    @Override
    public int getCompanyId(int userId) {
        QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        Company company = companyMapper.selectOne(queryWrapper);
        return company.getCompanyId();
    }
}
